<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        ul{
            list-style: none;
            background-color: white;
        }
        ul li{
            display: inline-block;
            padding: 10px 20px;
        }
        .item{
            display: none;
        }
    </style>
</head>
<body>
    <ul>
        <li>商品介绍</li>
        <li>规格与包装</li>
        <li>售后保障</li>
        <li>商品评价</li>
        <li>本店好评商品</li>
    </ul>
    <div class="item">商品介绍</div>
    <div class="item">规格与包装</div>
    <div class="item">售后保障</div>
    <div class="item">商品评价</div>
    <div class="item">本店好评商品</div>
    <script>
        var lis = document.querySelectorAll('li');
        var items= document.querySelectorAll('.item');
        for(var i =0;i<lis.length;i++){
            lis[i].setAttribute('data-index',i);//自定义属性
            // items[i].setAttribute('data-item',i);
            lis[i].onclick=function(){
                var index=this.getAttribute('data-index');
                for(var j=0;j<lis.length;j++){
                    lis[j].style.backgroundColor='';
                    lis[j].style.color='black';
                    items[j].style.display='none';
                }
                lis[index].style.backgroundColor='red';
                lis[index].style.color='#fff';
                items[index].style.display='block';
            }
        }
    </script>
</body>
</html>